// pages/order-info/index.js
var zUrl = getApp().globalData.zUrl;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_info:'',
    token:'',
    adviser: '',
    id:'',
  },
  tanchuang: function (e) {
    this.setData({
      tan: 1
    })
    this.setData({
      status: e.currentTarget.dataset.status
    })
  },
  close: function (e) {
    this.setData({
      tan: 2
    })
  },

  update:function(){
    var that =this
    wx.request({
      url: zUrl+'/api/order/update',
      method: 'POST',
      header: {
        'Cookie': 'laravel_session=' + wx.getStorageSync('laravel_session'),
        Accept: 'application/json',
        Authorization: 'Bearer ' + wx.getStorageSync('token')
      },
      data:{
        id:this.data.order_info.res.id,
        status:this.data.order_info.res.status,
        pid:this.data.order_info.res.p_id
      },
      success: function (res) {
        wx.hideLoading();
        if(res.data.code=='200'){
          wx.redirectTo({
            url: '/pages/order-info/index?id=' + that.data.order_info.res.id
          })
        }else{
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000
          })
        }
      },
      fail: function (error) {

      },
      complete: function (res) {

      }
    })
  },

  change_status:function(){
    var that=this
    wx.request({
      url: zUrl+'/api/order/editstatus',
      method: 'POST',
      header: {
        'Cookie': 'laravel_session=' + wx.getStorageSync('laravel_session'),
        Accept: 'application/json',
        Authorization: 'Bearer ' + wx.getStorageSync('token')
      },
      data: {
        id: this.data.order_info.res.id,
        status: this.data.status,
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.code == '200') {
          console.log(res.data.code)
          wx.redirectTo({
            url: '/pages/order-info/index?id=' + that.data.order_info.res.id
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000,
          })
        }
      },
      fail: function (error) {

      },
      complete: function (res) {

      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      adviser: wx.getStorageSync('adviser')
    }) 
this.setData({
  id:options.id
})
    var that = this;
    wx.request({
      url: zUrl+'/api/order/show',
      method: 'POST',
      header: {
        'Cookie': 'laravel_session=' + wx.getStorageSync('laravel_session'),
        Accept: 'application/json',
        Authorization: 'Bearer ' + wx.getStorageSync('token')
      },
      data:{
        id:options.id
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.code == 200) {
          that.setData({
            order_info: res.data.data
          })
        }else{
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000,
          })
        }
      },
      fail: function (error) {

      },
      complete: function (res) {

      }
    })
  },
  onPullDownRefresh: function () {
    wx.request({
      url: zUrl + '/api/order/show',
      data: {
        id: options.id
      },
      method: 'POST',
      header: {
        'Cookie': 'laravel_session=' + wx.getStorageSync('laravel_session'),
        Accept: 'application/json',
        Authorization: 'Bearer ' + wx.getStorageSync('token')
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.code == 200) {
          that.setData({
            order_info: res.data.data
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000,
          })
        }
       },
      fail: function (res) { },
      complete: function (res) {
        wx.stopPullDownRefresh();
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})